<?php
declare(strict_types = 1);
namespace app\admin\model;
use think\Config;
use think\Model;
class Order extends Model{
    public static function Order($data=[],$page=true,$query = []){
        $field=[
            'o.order_id','o.buyer_name','o.order_amount','s.order_status','o.add_time','p.payment_name',
        ];
        $model = self::field($field)
            ->alias('o')
            ->join(['ecm_order_status'=>'s'],'o.status=s.status_id','left')
            ->join(['ecm_payment'=>'p'],'o.payment_id=p.payment_id','left');
        if ($data['add_time1']!='' and $data['add_time2']!=''){
            $model->whereBetweenTime("add_time","{$data['add_time1']},{$data['add_time2']}");
        }
        if($data['order_status']!=''){
            foreach ($data['order_status'] as $v){
                $model->whereOr("status=$v");
            }
        }
        if ($data['order_amount1']!='' and $data['order_amount2']!=''){
            $model->whereBetween("order_amount","{$data['order_amount1']},{$data['order_amount2']}");
        }else if($data['order_amount1']='' and $data['order_amount2']!=''){
            $model->where("order_amount","{$data['order_amount2']}");
        }else if($data['order_amount1']!='' and $data['order_amount2']='')
        {
            $model->where("order_amount","{$data['order_amount1']}");
        }
        if ($page){
            $list_rows= \think\facade\Config::has('view.list_rows')?\think\facade\Config::get('view.list_rows'):15;
            return $model->paginate([
                'list_rows'=>  $list_rows,
                'query'    => $query,
            ]);
        }else{
            return $model->select();
        }
    }
    public static function test(){
        $model = self::field(true)
            ->table('ecm_order_status')
            ->select();
        return $model->select();
    }
}